<template>
  <div id="container">
    <div class="login-form">
      <el-form label-width="80px">
        <p class="title">旅游信息微信小程序服务端</p>
        <el-form-item label="用户名" prop="username" class="itemInfo">
          <el-input v-model="loginForm.username" placeholder="请输入用户名"></el-input>
        </el-form-item>

        <el-form-item label="密码" prop="password" class="itemInfo">
          <el-input type="password" v-model="loginForm.password" placeholder="请输入密码"></el-input>
        </el-form-item>

        <el-form-item class="itemButton">
          <el-button class="button" type="primary" @click="login">登 录</el-button>
          <el-button class="button" type="info" @click="reset">重 置</el-button>
        </el-form-item>
      </el-form>
           <div class="MImaWrapper">
      </div>
    </div>
  </div>
</template>

<script setup>
  import { ref } from 'vue'
  import { loginApi } from '../../api/login';
  import { ElMessage } from 'element-plus';
  import { useRouter } from 'vue-router'
  import { useLoginEmpStore } from '../../stores/loginEmp';
  
  let loginForm = ref({ username: '', password: '' })
  const loginEmpStore = useLoginEmpStore()
  const router = useRouter()

  const login = async () => {
    const result = await loginApi(loginForm.value)
    if (result.code) {
      ElMessage.success('登录成功') 
      console.log(result.data);
      localStorage.setItem('token', result.data.token)
      loginEmpStore.setLoginEmp(result.data)
      router.push('/layout')
    } else {
      ElMessage.error(result.msg)
    }
  }

  const reset = () => {
    loginForm.value = { username: '', password: '' }
  }
</script>

<style scoped>
#container {
  padding: 10%;
  height: 100vh;
  background-image: url('../../public/loginBG.png');
  background-repeat: no-repeat;
  background-size: cover;
  display: flex;
  justify-content: center;
  align-items: center;
}
.MImaWrapper{
  margin: 0 auto;
  width: 40%;
  /* border: 1px solid red; */
  display: flex;
  justify-content: space-between;
}

.updateMIma{
  color: rgb(255, 133, 33);
  text-decoration: underline;
}
.forgetMIma{
    color: rgb(184, 163, 255);
    text-decoration: underline;
}

.updateMIma:hover{
  color: red;
  text-decoration: underline;
  cursor: pointer;
}
.forgetMIma:hover{
  color: rgb(84, 31, 255);
  text-decoration: underline;
  cursor: pointer;
}

.login-form {
  max-width: 500px;
  padding: 40px;
  margin: 0 auto;
  border-radius: 12px;
  backdrop-filter: blur(8px); /* 背景模糊效果 */
  background-color: rgba(255, 255, 255, 0.5); /* 半透明白色背景 */
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15); /* 增强阴影效果 */
  /* border: 1px solid rgba(255, 255, 255, 0.3); 半透明边框 */
  border: 2px solid rgba(255, 16, 16, 0.4);
}

.title {
  font-size: 32px;
  font-family: '楷体';
  text-align: center;
  margin-bottom: 35px;
  font-weight: bold;
  color: #333;
}

.itemInfo {
  width: 80%; /* 自适应宽度 */
  margin-bottom: 20px;
}

.itemInfo .el-input {
  width: 100%;
}

.itemButton{
  /* margin-left: -30px; */
}

.button {
  margin-top: 25px;
  width: 100px;
  height: 40px;
  font-size: 16px;
}

/* 响应式调整 */
@media (max-width: 600px) {
  .login-form {
    padding: 30px 20px;
    max-width: 90%;
  }
  
  .title {
    font-size: 28px;
  }
}
</style>